Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pure pursuit library #23387

Merged
merged 1 commit into from
Jul 18, 2024
Merged

Add pure pursuit library #23387

merged 1 commit into from
Jul 18, 2024

Conversation

chfriedrich98
Copy link
Contributor

@chfriedrich98 chfriedrich98 commented Jul 10, 2024

Solved Problem

The pure pursuit algorithm is used by the new ackermann rover module and soon also by the updated differential rover and the upcoming boat module.
Creating a library for the algorithm avoids having to copy the same code into all the modules.

Solution

The algorithm calculates the intersection point between a circle around the vehicle and the line segment connecting the previous and current waypoint and returns the heading towards that point. The radius of the circle around the vehicle is used to tune the controller and is often referred to as look-ahead distance ($l_d$).
image

Test coverage

  • Unit test for edge cases
  • SITL tested (ackermann rover module)

@chfriedrich98 chfriedrich98 self-assigned this Jul 10, 2024
Copy link
Member

@Jaeyoung-Lim Jaeyoung-Lim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Added some minor stylistic comments

src/lib/pure_pursuit/PurePursuit.hpp Show resolved Hide resolved
src/lib/pure_pursuit/PurePursuit.hpp Outdated Show resolved Hide resolved
src/lib/pure_pursuit/PurePursuit.cpp Outdated Show resolved Hide resolved
src/lib/pure_pursuit/PurePursuit.cpp Outdated Show resolved Hide resolved
src/lib/pure_pursuit/PurePursuit.cpp Outdated Show resolved Hide resolved
src/lib/pure_pursuit/PurePursuit.cpp Outdated Show resolved Hide resolved
src/lib/pure_pursuit/PurePursuit.cpp Outdated Show resolved Hide resolved
@chfriedrich98
Copy link
Contributor Author

@Jaeyoung-Lim Thanks for the review!
I implemented most of your suggestions and left some comments.

src/lib/pure_pursuit/PurePursuit.cpp Outdated Show resolved Hide resolved
src/lib/pure_pursuit/PurePursuit.cpp Outdated Show resolved Hide resolved
src/lib/pure_pursuit/PurePursuit.cpp Outdated Show resolved Hide resolved
src/lib/pure_pursuit/PurePursuit.cpp Outdated Show resolved Hide resolved
src/lib/pure_pursuit/PurePursuit.cpp Outdated Show resolved Hide resolved
src/lib/pure_pursuit/PurePursuit.cpp Outdated Show resolved Hide resolved
@chfriedrich98
Copy link
Contributor Author

chfriedrich98 commented Jul 17, 2024

After discussing the implementation with @bresch I made some major changes to how the intersection point is calculated. It is now done using vectors which eliminates many of the edgecases I had to consider.
Also to keep everything consistent with @Jaeyoung-Lim's input:

If you return a zero, there is no way outside of the library to detect whether if the input you have provided is valid or not.
It is actually a positive feature if something breaks down the line. It means that you need to handle these cases explicitly for your runtime application, rather than concealing it in the library. The way it is implemented now, an invalid position estimate will result in aligning the vehicle into zero heading, which is a behavior that is unrelated to the failure.

the algorithm now returns NAN if any of the inputs are invalid rather than using the bearing to the current waypoint as a fallback.

@chfriedrich98 chfriedrich98 requested review from Jaeyoung-Lim and removed request for sfuhrer and PerFrivik July 18, 2024 09:52
Copy link
Member

@Jaeyoung-Lim Jaeyoung-Lim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much nicer :)

@chfriedrich98
Copy link
Contributor Author

rebased on main and squashed

@bresch bresch merged commit a42dc21 into PX4:main Jul 18, 2024
90 checks passed
@chfriedrich98 chfriedrich98 deleted the pure_pursuit branch August 29, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants